<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\StaffService;
use App\Utility\Upload;
use Illuminate\Http\Request;

class StaffController extends BaseController
{
    //登录

    // 列表
    public function index(Request $request)
    {
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = StaffService::index($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    // 详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', 0);
        $res = StaffService::getOne($id);
        return self::toJson(0, '', $res);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('uid', 0);
        $pas['title'] = $request->post('title', '');
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['depart_lead'] = $request->post('depart_lead', 0);
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['is_able'] = $request->post('is_able', 0);
        $res = StaffService::modify($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //设置密码
    public function setPwd(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['upwd'] = $request->post('upwd', '');
        $pas['pwdnew'] = $request->post('pwdnew', '');
        $pas['pwdnew2'] = $request->post('pwdnew2', '');
        if ($pas['pwdnew'] != $pas['pwdnew2']) {
            return self::toJson(-2, '2次新密码不一致');
        }
        $res = StaffService::setPwd($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //设置密码
    public function setPasswd(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['pwd'] = $request->post('pwd', '');
        $pas['pwdnew'] = $request->post('pwdnew', '');
        $res = StaffService::setPasswd($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}